package com.nash.demands;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.SoapFault;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import android.provider.Settings.Secure;

public class Transport extends Object {

  public final String NAMESPACE = "http://demands.dostavka-m.ru/";
  public final String URL = "http://demands.dostavka-m.ru/soap/demands-android.php";

  public SoapObject LoadBySoap( final String method_name, final int ver, final String android_id, 
        final String license_id, final int user_id, final SoapObject soapObj) throws DemandsException {

    SoapObject request = new SoapObject(NAMESPACE, method_name);

    request.addProperty("device_id", android_id);
    request.addProperty("license_id", license_id);
    request.addProperty("user_id", ""+user_id); //105  294
    request.addProperty("version", method_name == null ? "0" : ""+ver);
    if (soapObj!=null)
      request.addSoapObject(soapObj);

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.setOutputSoapObject(request);
    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
    SoapObject res = null;
    try {
      //androidHttpTransport.debug=true;
      androidHttpTransport.call("http://demands.dostavka-m.ru/" + method_name, envelope);
      res = (SoapObject)envelope.getResponse();
      //res2 = (SoapObject) ((Vector<SoapObject>) res).get(1);
    } catch (SoapFault eSoap) {
      throw new DemandsException(eSoap);
    } catch (Exception e) {
      throw new DemandsException(e);
    }
    return res;
  }
}
